package com.lw.controller;

import com.lw.service.PermissionService;
import com.lw.system.Permission;
import com.lw.utils.Result;
import com.lw.utils.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class PermissionController {
    @Autowired
    PermissionService permissionService;
    @PostMapping("/permission")
    public Result save(@RequestBody Map<String,Object> map) throws Exception {
        permissionService.save( map );
        return Result.SUCCESS();
    }
    @PutMapping("/permission")
    public Result update(@RequestBody Map<String,Object> map) throws Exception {
        permissionService.update( map );
        return Result.SUCCESS();
    }
    @GetMapping("/permission")
    public Result findAll(@RequestParam Map<String,Object> map){
        List<Permission> permissions=permissionService.findAll( map );
        return new Result( ResultCode.SUCCESS,permissions );
    }
    @GetMapping("/yi")
    public Result detail(@RequestParam(value = "id") String id){
        Map<String, Object> permission = permissionService.findById( id );
        return new Result( ResultCode.SUCCESS,permission );
    }
    @DeleteMapping("/permission")
    public Result delete(@RequestBody Map<String ,Object> map){
        permissionService.delete( map );
        return Result.SUCCESS();
    }
}
